package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.BranchBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/9 0009.
 */

public class BranchListAdapter extends BaseAdapter {
    private ArrayList<BranchBean.ListInfo> list;
    private Context context;
    private LayoutInflater inflater;
    public  BranchListAdapter(Context context,ArrayList<BranchBean.ListInfo> list){

        this.list=list;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
     MyViewHolder myViewHolder;
     if (convertView==null){
       myViewHolder=new MyViewHolder();
       convertView=inflater.inflate(R.layout.item_branchlist,parent,false);
       myViewHolder.hospitalAddress=convertView.findViewById(R.id.hospitalAddress);
         myViewHolder.hopitalImg=convertView.findViewById(R.id.hopitalImg);
         myViewHolder.hospitalName=convertView.findViewById(R.id.hospitalName);
         myViewHolder.hospitalTelephone=convertView.findViewById(R.id.hospitalTelephone);
         convertView.setTag(myViewHolder);
     }else {
         myViewHolder= (MyViewHolder) convertView.getTag();
     }
        myViewHolder.hospitalName.setText(list.get(position).getName());
        myViewHolder.hospitalTelephone.setText("电话: "+list.get(position).getLink_phone());
        myViewHolder.hospitalAddress.setText("地址: "+list.get(position).getAddress());
        myViewHolder.hopitalImg.setBackgroundDrawable(context.getResources().getDrawable(list.get(position).getIcon()));
        return convertView;
    }
    class MyViewHolder{
        ImageView hopitalImg;
        TextView hospitalName,hospitalAddress,hospitalTelephone;
    }
}
